package gk.gkapi.impl.db.hashmap;

import gk.gkapi.DB;
import gk.gkapi.DBMap;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


public class DBHashMapImpl implements DB {

	Map<String, DBMap<?, ?>> collections = new ConcurrentHashMap<String, DBMap<?, ?>>();

	@SuppressWarnings("unchecked")
	@Override
	synchronized public <K, V> DBMap<K, V> getDBCollection(String name, Class<K> keyClass, Class<V> valueClass) {
		if (name == null) {
			throw new IllegalArgumentException("Collection name can not be null.");
		}
		DBMap<K, V> dbMap = (DBMap<K, V>) collections.get(name);
		if (dbMap == null) {
			dbMap = new DBMapHashMapImpl<K, V>(keyClass, valueClass);
			collections.put(name, dbMap);
		}

		return dbMap;
	}

}
